package com.xhd.config;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.cache.CacheMgr;
import com.xhd.cache.UseCache;

public class BizObjClass implements UseCache {
	private Class jm204 = null;
	private HashMap jm205 = null;
	private String jm21 = null;
	private String jm206 = null;
	private HashMap jm207 = null;
	private HashMap jm208 = new HashMap(2);
	private Method jm209 = null;
	private static HashMap jm26 = new HashMap(256);
	private static boolean jm158 = false;
	private static final Log jm9;
	static Class jm10;

	static {
		Class tmp20_17 = jm10;
		if (tmp20_17 == null) {

			try {
				BizObjClass.jm10 = Class
						.forName("com.sinocc.base.config.BizObjClass");
			} catch (ClassNotFoundException localClassNotFoundException) {
				throw new NoClassDefFoundError(localClassNotFoundException
						.getMessage());
			}
		}
		jm9 = LogFactory.getLog(tmp20_17);
	}

	private BizObjClass(Class paramClass) {
		jm124(paramClass);
		if (jm158)
			return;
		jm158 = true;
		CacheMgr.registerCache(this);
	}

	public static BizObjClass getInstance(Class paramClass) {
		BizObjClass localBizObjClass = (BizObjClass) jm26.get(paramClass);
		if (localBizObjClass == null)
			if (paramClass != null) {
				localBizObjClass = new BizObjClass(paramClass);
				jm26.put(paramClass, localBizObjClass);
			} else {
				jm9.error("Class can't null.");
			}
		return localBizObjClass;
	}

	public static BizObjClass getInstance(String paramString) {
		int i = paramString.indexOf(32);
		if (i > 0)
			paramString = paramString.substring(0, i);
		Class localClass = BizObjFactory.getInstance().getBizClass(paramString);
		if (localClass == null) {
			if (paramString.startsWith("user_"))
				return null;
			return null;
		}
		return getInstance(localClass);
	}

	public static BizObjClass getInstance(Object paramObject) {
		BizObjClass localBizObjClass = (BizObjClass) jm26.get(paramObject
				.getClass());
		if (localBizObjClass == null) {
			localBizObjClass = new BizObjClass(paramObject.getClass());
			jm26.put(paramObject.getClass(), localBizObjClass);
		}
		return localBizObjClass;
	}

	private void jm124(Class paramClass) {
		this.jm206 = paramClass.getName();
		int i = this.jm206.lastIndexOf(46);
		if (i > 0)
			this.jm21 = this.jm206.substring(i + 1).toLowerCase();
		else
			this.jm21 = this.jm206.toLowerCase();
		this.jm204 = paramClass;
		Field[] arrayOfField = this.jm204.getFields();
		HashMap localHashMap = new HashMap(arrayOfField.length + 1);
		localHashMap.put("_all_", arrayOfField);
		for (int j = 0; j < arrayOfField.length; ++j)
			localHashMap.put(arrayOfField[j].getName().toLowerCase(),
					arrayOfField[j]);
		this.jm205 = localHashMap;
		localHashMap = null;
		Method[] arrayOfMethod = this.jm204.getMethods();
		int k = (arrayOfMethod == null) ? 0 : arrayOfMethod.length;
		this.jm207 = new HashMap(k);
		for (int l = 0; l < k; ++l) {
			String str = arrayOfMethod[l].getName().toLowerCase();
			if (!(str.startsWith("do")))
				continue;
			Class[] arrayOfClass = arrayOfMethod[l].getParameterTypes();
			if ((arrayOfClass == null) || (arrayOfClass.length == 0)) {
				this.jm207.put(str, arrayOfMethod[l]);
			} else {
				if ((1 != arrayOfClass.length)
						|| (!(str.equals("dotransaction"))))
					continue;
				this.jm209 = arrayOfMethod[l];
			}
		}
	}

	public String getName() {
		return this.jm21;
	}

	public String getFullName() {
		return this.jm206;
	}

	public static String getObjName(Object paramObject) {
		String str = paramObject.getClass().getName();
		int i = str.lastIndexOf(46);
		if (i > 0)
			str = str.substring(i + 1);
		return str.toLowerCase();
	}

	public Class getBizClass() {
		return this.jm204;
	}

	public Field getField(String paramString) {
		return ((Field) this.jm205.get(paramString.toLowerCase()));
	}

	public Field[] getFields() {
		return ((Field[]) this.jm205.get("_all_"));
	}

	public boolean isString(Field paramField) {
		String str = paramField.getType().getName();
		return str.endsWith(".String");
	}

	public boolean isNumber(Field paramField) {
		String str = paramField.getType().getName();
		return (("int".equals(str)) || (str.endsWith("BigDecimal")));
	}

	public String findKeyField(String paramString) {
		String str = this.jm21;
		if (this.jm21.indexOf("_") > 0)
			paramString = "_" + paramString;
		for (int i = 0; i < 5; ++i) {
			str = str.substring(1);
			if (this.jm205.containsKey(str + paramString))
				return str + paramString;
			if (str.length() < 1)
				break;
		}
		return null;
	}

	public Method getActionMethod(String paramString) {
		return ((Method) this.jm207.get("do" + paramString));
	}

	public Method getActionsMethod() {
		return this.jm209;
	}

	public Method getEventMethod(String paramString) {
		if (this.jm208.containsKey(paramString))
			return ((Method) this.jm208.get(paramString));
		Method[] arrayOfMethod = this.jm204.getMethods();
		int i = (arrayOfMethod == null) ? 0 : arrayOfMethod.length;
		for (int j = 0; j < i; ++j) {
			String str = arrayOfMethod[j].getName().toLowerCase();
			if (!(str.equals(paramString)))
				continue;
			this.jm208.put(paramString, arrayOfMethod[j]);
			return arrayOfMethod[j];
		}
		this.jm208.put(paramString, null);
		return null;
	}

	public boolean clearCache() {
		jm26.clear();
		return true;
	}

	public int cacheSize() {
		return jm26.size();
	}

	public Object cacheData() {
		return jm26;
	}
}
